package servlet;

import java.io.IOException;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import entity.Goods;

@WebServlet("/index")
public class IndexServlet extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("UTF-8");//这是一个坑，前端传数据进来，要先判断它编码是否正确
		resp.setContentType("text/html;charset=UTF-8");//防止中文乱码
		
		if(req.getCookies()!=null) {//判断当前的request中是否有cookie
			Cookie[] cookies = req.getCookies();
	        for (Cookie c:cookies){
	        	if("uid".equals(c.getName())) {//选择cookie指定的key值
	        		req.setAttribute("uid", c.getValue());
	        	}
	        }
		}

		req.getRequestDispatcher("index.jsp").forward(req, resp);


	}
}